﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Engine.Rule;
using Engine.RuleEditor.Properties;

namespace Engine.RuleEditor
{
    public class FormStatTypesEditor : FormAttributeTypesEditor
    {
        private List<StatType> statTypes;
        public List<StatType> StatTypes
        {
            get { return statTypes; }
            set { statTypes = value; }
        }

        public FormStatTypesEditor(List<StatType> statTypes)
            : base("Stat Types Editor", Resources.database)
        {
            StatTypes = statTypes;

            for (int sIndex = 0; sIndex < statTypes.Count; sIndex++)
            {
                StatType statType = statTypes[sIndex];

                DataGridViewTextBoxCell cellName = new DataGridViewTextBoxCell();
                cellName.Value = statType.Name;
                DataGridViewTextBoxCell cellDescription = new DataGridViewTextBoxCell();
                cellDescription.Value = statType.Description;
                DataGridViewRow row = new DataGridViewRow();
                row.Cells.Add(cellName);
                row.Cells.Add(cellDescription);

                DataGridTypes.Rows.Add(row);
            }
        }

        protected override void buttonSave_Click(object sender, EventArgs e)
        {
            StatTypes.Clear();
            for (int rIndex = 0; rIndex < DataGridTypes.Rows.Count - 1; rIndex++)
            {
                object objName = DataGridTypes[0,rIndex].Value;
                object objDescription = DataGridTypes[1,rIndex].Value;
                string statName = (objName != null ? objName.ToString() : null);
                string statDescription = (objDescription != null ? objDescription.ToString() : null);
                StatType statType = new StatType(statName, statDescription);
                StatTypes.Add(statType);
            }
            base.buttonSave_Click(sender, e);
        }
    }
}
